using IQIGame.Onigao.GameAOT;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public partial class UIMapManager
    {
        private class UIEntityTracerSymbol : UINormalMapSymbol
        {
            public override void Reset()
            {
                base.Reset();
                CodeBasedBlinkEffectGenerator.Instance.Destroy(_canvasGroup);
            }

            protected override void OnInit()
            {
                base.OnInit();
                _canvasGroup = gameObject.GetOrAddComponent<CanvasGroup>();
                CodeBasedBlinkEffectGenerator.Instance.Generate(_canvasGroup, 1f, 1f, 0.2f);
            }

            protected override void Draw()
            {
                base.Draw();
                ui.icon.raycastTarget = false;
            }

            protected override void UpdateTransform()
            {
                var playerWorldPos = GameplayAreaManager.Instance.curSceneArea.GetPlayerAvatarEntity().transform.position;
                var playerPos = owner.PositionWorldToMap(playerWorldPos);
                var targetPos = owner.PositionWorldToMap(data.worldPosition);
                var distance = Vector2.Distance(playerPos, targetPos);
                transform.localPosition = playerPos + Mathf.Min(owner.curContainer.radius / owner.transform.localScale.x, distance) *
                    (targetPos - playerPos).normalized;
            }

            private CanvasGroup _canvasGroup;
        }
    }
}